<template>
  <div>

    <el-dialog width="80%" title="客户信息" :visible.sync="dialogTableVisible">

      <el-button @click="resetDateFilter">重置</el-button>
      <el-button @click="clearFilter">清除所有</el-button>

      <el-table
        @selection-change="handleSelectionChange"
        border
        ref="filterTable"
        size="medium"
        :data="tableData"
        :height="600"
        :max-height="600"
        stripe
        tooltip-effect="light"
        style="width: 100%;">
        <template #empty>
          <div style="padding: 10px; color: #999; text-align: center;">
            <i class="el-icon-warning"></i> 暂无数据，请稍后再试
          </div>
        </template>
        <el-table-column
          type="selection"
          width="55">
        </el-table-column>
        <el-table-column
          prop="id"
          label="编号"
          sortable
          column-key="id"
          :filters="getIdFilter"
          :filter-method="filterHandler"
          width="100">
        </el-table-column>
        <el-table-column
          prop="industry"
          label="行业"
          width="120"
          column-key="industry"
          :filters="getIndustryFilter"
          :filter-method="filterHandler">
          <template slot-scope="scope">
            <i class="el-icon-office-building"></i>
            <span style="margin-left: 5px;">{{ scope.row.industry }}</span>
          </template>
        </el-table-column>
        <el-table-column
          prop="companyName"
          label="单位名称"
          width="180"
          column-key="companyName"
          :filters="getCompanyFilter"
          :filter-method="filterHandler"
          sortable>
          <template slot-scope="scope">
            <i class="el-icon-s-shop"></i>
            <span style="margin-left: 5px;">{{ scope.row.companyName }}</span>
          </template>
        </el-table-column>
        <el-table-column
          prop="subsidiary"
          label="下属单位"
          width="180">
        </el-table-column>
        <el-table-column
          prop="address"
          label="地址"
          width="200">
          <template slot-scope="scope">
            <i class="el-icon-location"></i>
            <span style="margin-left: 5px;">{{ scope.row.address }}</span>
          </template>
        </el-table-column>
        <el-table-column
          prop="contact1"
          label="联系人一"
          width="120">
          <template slot-scope="scope">
            <i class="el-icon-user"></i>
            <span style="margin-left: 5px;">{{ scope.row.contact1 }}</span>
          </template>
        </el-table-column>
        <el-table-column
          prop="phone1"
          label="电话一"
          width="140">
          <template slot-scope="scope">
            <i class="el-icon-phone"></i>
            <span style="margin-left: 5px;">{{ scope.row.phone1 }}</span>
          </template>
        </el-table-column>
        <el-table-column
          prop="contact2"
          label="联系人二"
          width="120">
          <template slot-scope="scope">
            <i class="el-icon-user"></i>
            <span style="margin-left: 5px;">{{ scope.row.contact2 }}</span>
          </template>
        </el-table-column>
        <el-table-column
          prop="phone2"
          label="电话二"
          width="140">
          <template slot-scope="scope">
            <i class="el-icon-phone"></i>
            <span style="margin-left: 5px;">{{ scope.row.phone2 }}</span>
          </template>
        </el-table-column>
        <el-table-column
          prop="contact3"
          label="联系人三"
          width="120">
          <template slot-scope="scope">
            <i class="el-icon-user"></i>
            <span style="margin-left: 5px;">{{ scope.row.contact3 }}</span>
          </template>
        </el-table-column>
        <el-table-column
          prop="phone3"
          label="电话三"
          width="140">
          <template slot-scope="scope">
            <i class="el-icon-phone"></i>
            <span style="margin-left: 5px;">{{ scope.row.phone3 }}</span>
          </template>
        </el-table-column>
        <el-table-column
          fixed="right"
          label="操作"
          width="150">
          <template slot-scope="scope">
            <el-button @click="addHandleClick(scope.row)" type="text" size="small">查看</el-button>
            <el-button type="text" @click="modifyHandleClick(scope.row)" size="small">编辑</el-button>
          </template>
        </el-table-column>
      </el-table>
    </el-dialog>
  </div>
</template>

<script>
import {mapListLabel} from "@/tool/util";
import detailCustomerTable from "@/components/Detail/detailCustomerTable.vue";
import {tableCustomer} from '@/data/customerData'
import store from "@/store";
import {mapGetters} from "vuex";
export default {
  name: "customerDialog",
  components: {
    detailCustomerTable,
  },
  computed: {
    ...mapGetters(['getDetails']),
    store() {
      return store
    },
    getIdFilter() {
      return tableCustomer.map(item => ({
        text: item.id,
        value: item.id
      }));
    },
    getIndustryFilter() {
      const industries = [...new Set(tableCustomer.map(item => item.industry))];
      return industries.map(industry => ({
        text: industry,
        value: industry
      }));
    },
    getCompanyFilter() {
      const companies = [...new Set(tableCustomer.map(item => item.companyName))];
      return companies.map(company => ({
        text: company,
        value: company
      }));
    },
    getTableData() {
      return tableCustomer
    }
  },
  data() {
    return {
      dialogTableVisible: false,
      gridData: [],
      multipleSelection: [],
      tableData: []
    }
  },
  mounted() {
    this.searchCustomer()
  },
  methods: {
    searchCustomer() {
      this.tableData = this.getTableData;
      console.log('客户信息加载完成');
    },
    resetDateFilter() {
      this.$refs.filterTable.clearFilter('id');
    },
    clearFilter() {
      this.$refs.filterTable.clearFilter();
    },
    formatter(row, column) {
      return row.address;
    },
    filterTag(value, row) {
      return row.tag === value;
    },
    filterHandler(value, row, column) {
      const property = column['property'];
      return row[property] === value;
    },
    addHandleClick(row) {
      console.log(row)
    //   在这个地方显示这个查看的内容
      this.showDeadline(row)
    },
    modifyHandleClick(row) {
      console.log(row)
    //  在这个地方显示一下这个编辑的数据回显的菜单就行了
    },
    handleSelectionChange(row) {
      this.multipleSelection = row
      console.log(this.multipleSelection)
    }
  },
  props: {
    propName: {
      type: Number,
      default: 0
    },
    showCustomerDialog: {
      type: Function,
      default: () => {
      },
      required: false
    }
  },
}
</script>
